import { ArgumentsHost, Catch, ExceptionFilter, HttpStatus } from '@nestjs/common';
import { Prisma } from '@prisma/client';

@Catch()
export class PrismaClientFilter implements ExceptionFilter {
  catch(exception: Prisma.PrismaClientKnownRequestError, host: ArgumentsHost) {
    console.log('PrismaClientFilter', exception);
    const ctx = host.switchToHttp();
    const responce = ctx.getResponse();
    const message = exception.message;
    const status = HttpStatus.BAD_REQUEST;
    responce.status(status).json({
      code: status,
      success: false,
      message,
    });
  }
}
